import 'dart:convert';
import 'dart:math';
import 'package:crypto/crypto.dart' as CMd5;

// md5 md5加密
String md5(String str) {
  return CMd5.md5.convert(utf8.encode(str)).toString();
}

// nwo 现在时间 Y-m-d H:i:s
String now() {
  DateTime now = DateTime.now();
  // 格式化日期和时间
  return '${now.year.toString().padLeft(4, '0')}-'
      '${now.month.toString().padLeft(2, '0')}-'
      '${now.day.toString().padLeft(2, '0')} '
      '${now.hour.toString().padLeft(2, '0')}:'
      '${now.minute.toString().padLeft(2, '0')}:'
      '${now.second.toString().padLeft(2, '0')}';
}

// generateRandomString 生成随机字符串
String generateRandomString(int length) {
  const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  Random random = Random();
  return String.fromCharCodes(Iterable.generate(
      length,
          (_) => characters.codeUnitAt(random.nextInt(characters.length))
  ));
}